#include<iostream>
#include<bitset>
#include<stdexcept>
#include<string>

using namespace std;

int
main(void) {
	try {
		string str = "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111";
		bitset<65> bi(str,0,68);
		int len = bi.size();
		int i = len - 1;
	    while (!bi.test(i)) {
			i--;
		}
		cout << "i:" << i << endl;
	    cout << "length" << bi.size() << endl;	
		if (i+1 > 64)
			throw overflow_error("can not convert to unsigned long !");
		else

			cout << bi.to_ulong() << endl;
	} catch(overflow_error err) {
		cout << err.what() << endl;
	}
	return 0;
}
